package leetcode_301_400;

public class LeeCode_378 {
    public static void main(String[] args) {

    }
    private static int kthSmallest(int[][] matrix, int k) {
        int n = matrix.length;
        int[] is = new int[n];
        int ans = 0;
        int j = 0;
        while (j < k){
            int min = Integer.MAX_VALUE;
            int mini = 0;
            for (int i = 0; i < n; i++) {
                if (is[i] >= n)
                    continue;
                if (matrix[i][is[i]] < min){
                    min = matrix[i][is[i]];
                    mini = i;
                }
            }
            is[mini]++;
            j++;
            ans = min;
        }
        return ans;
    }
}
